import { logout } from '@/api/user'

const user = {
  state: {
    token: '',
    name: '',
    avatar: ''
  },

  mutations: {
    SET_TOKEN: (state, token) => {
      state.token = token
    },
    SET_NAME: (state, name) => {
      state.name = name
    },
    SET_AVATAR: (state, avatar) => {
      state.avatar = avatar
    }
  },

  actions: {
    // 登出
    Logout({ commit, state }) {
      return new Promise(resolve => {
        logout()
          .then(() => {
            commit('SET_TOKEN', '')
            resolve()
          })
          .catch(() => {
            resolve()
          })
          .finally(() => {})
      })
    }
  }
}

export default user
